
package com.scs.application.modules.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.base.entity.MaterialBidItem;
import com.scs.application.modules.base.mapper.MaterialBidItemMapper;
import com.scs.application.modules.base.request.MaterialBidItemQueryRequest;
import com.scs.application.modules.base.service.MaterialBidItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 耗材报价明细 service 实现
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class MaterialBidItemServiceImpl extends BaseServiceImpl<MaterialBidItemMapper, MaterialBidItem> implements MaterialBidItemService {

    @Override
    public List<MaterialBidItem> list(MaterialBidItemQueryRequest request) {
        List<MaterialBidItem> list = this.list(getQueryWrapper(request));
        return list;
    }

    @Override
    public List<MaterialBidItem> listVO(MaterialBidItemQueryRequest request) {
        List<MaterialBidItem> list = this.baseMapper.listVO(request);
        return list;
    }

    @Override
    public IPage<MaterialBidItem> page(MaterialBidItemQueryRequest request) {
        IPage page = this.page(request.getPage(), getQueryWrapper(request));
        return page;
    }


    private QueryWrapper<MaterialBidItem> getQueryWrapper(MaterialBidItemQueryRequest request) {
        return Wrappers.<MaterialBidItem>query()
                .eq(StringUtils.isNotBlank(request.getBidId()), "bid_id", request.getBidId())
                .eq(StringUtils.isNotBlank(request.getBiddingStrategies()), "bidding_strategies", request.getBiddingStrategies())
                .like(StringUtils.isNotBlank(request.getMaterialName()), "material_name", request.getMaterialName())
                .like(StringUtils.isNotBlank(request.getMaterialSpec()), "material_spec", request.getMaterialSpec())
                .between(StringUtils.isNotBlank(request.getBeginSkuUnit()) && StringUtils.isNotBlank(request.getEndSkuUnit()), "sku_unit", request.getBeginSkuUnit(), request.getEndSkuUnit())
                .orderByDesc("gmt_modified");
    }
}
